package com.ruoyi.mdm.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mdm.mapper.ChannelInfoMapper;
import com.ruoyi.mdm.domain.ChannelInfo;
import com.ruoyi.mdm.service.IChannelInfoService;

/**
 * 渠道信息Service业务层处理
 *
 * @author shiseido
 * @date 2025-02-28
 */
@Service
public class ChannelInfoServiceImpl implements IChannelInfoService {
    @Autowired
    private ChannelInfoMapper channelInfoMapper;

    /**
     * 查询渠道信息
     *
     * @param id 渠道信息主键
     * @return 渠道信息
     */
    @Override
    public ChannelInfo selectChannelInfoById(Long id) {
        return channelInfoMapper.selectChannelInfoById(id);
    }

    /**
     * 查询渠道信息列表
     *
     * @param channelInfo 渠道信息
     * @return 渠道信息
     */
    @Override
    public List<ChannelInfo> selectChannelInfoList(ChannelInfo channelInfo) {
        return channelInfoMapper.selectChannelInfoList(channelInfo);
    }

    /**
     * 新增渠道信息
     *
     * @param channelInfo 渠道信息
     * @return 结果
     */
    @Override
    public int insertChannelInfo(ChannelInfo channelInfo) {
        channelInfo.setCreateTime(DateUtils.getNowDate());
        channelInfo.setUpdateTime(DateUtils.getNowDate());
        return channelInfoMapper.insertChannelInfo(channelInfo);
    }

    /**
     * 修改渠道信息
     *
     * @param channelInfo 渠道信息
     * @return 结果
     */
    @Override
    public int updateChannelInfo(ChannelInfo channelInfo) {
        channelInfo.setUpdateTime(DateUtils.getNowDate());
        return channelInfoMapper.updateChannelInfo(channelInfo);
    }

    /**
     * 校验渠道编码是否存在
     *
     * @param channelInfo 渠道信息
     * @return 结果
     */
    @Override
    public boolean checkChannelCodeExist(ChannelInfo channelInfo) {
        Long id = StringUtils.isNull(channelInfo.getId()) ? -1L : channelInfo.getId();
        ChannelInfo info = channelInfoMapper.selectChannelInfoByCode(channelInfo.getChannelCode());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue()) {
            return false;
        }
        return true;
    }

    /**
     * 批量删除渠道信息
     *
     * @param ids 需要删除的渠道信息主键
     * @return 结果
     */
    @Override
    public int deleteChannelInfoByIds(Long[] ids) {
        return channelInfoMapper.deleteChannelInfoByIds(ids);
    }

    /**
     * 删除渠道信息信息
     *
     * @param id 渠道信息主键
     * @return 结果
     */
    @Override
    public int deleteChannelInfoById(Long id) {
        return channelInfoMapper.deleteChannelInfoById(id);
    }
}
